#!/usr/bin/python
import sys
import time
from abrirpuerta import abrirpuerta
from cerrarpuerta import cerrarpuerta
import Adafruit_DHT
DHT_TYPE = Adafruit_DHT.DHT11
DHT_PIN = 4 #value of GPIO_PIN
limite_abrir = 16
limite_cerrar = 13

while True:
	humidity, temperature = Adafruit_DHT.read_retry(DHT_TYPE, DHT_PIN)
	if humidity is None or temperature is None:	
		#time.sleep(2)
		continue
	print 'Temperature: {0:0.1f} C'.format(temperature)
	print 'Humidity: {0:0.1f} %'.format(humidity)
	if temperature >= limite_abrir:
		print 'abrir'
		abrirpuerta()
	if temperature <= limite_cerrar:
		print 'cerrar'
		cerrarpuerta()

